package com.hspedu.Writer;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @Author Stringzhua
 * @Date 2024/3/16 20:07
 * description:演示BufferedWriter的使用
 */
public class BufferedWriter_ {
    public static void main(String[] args) throws IOException {
        String filePath = "e:\\qiyeke\\filecontroller\\test.txt";
        //创建BufferedWriter对象
        //说明:
        //1.new FileWriter(filePath,true) 表示以追加的方式写入
        //2.new FileWriter(filePath) 表示以覆盖的方式写入
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filePath));
        bufferedWriter.write("hello1,爪爪吃蒸饺");
        bufferedWriter.newLine();//插入一个系统相关的换行
        bufferedWriter.write("hello2,爪爪吃蒸饺");
        //插入一个换行
        bufferedWriter.newLine();
        bufferedWriter.write("hello3,爪爪吃蒸饺");
        bufferedWriter.newLine();
        //关闭外层流即可,传入的new FileWriter(filePath),会在底层关闭
        bufferedWriter.close();
    }
}
